using KPIS.GERP.Models;
using KPIS.GERP.Models.Class;
using KPIS.GERP.Models.ICM;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Web.Mvc;

namespace KPIS.GERP.WCF.GIMS
{
    [ServiceContract]
    public interface IIcmMasLookUpTypeService
    {
        [OperationContract]
        IEnumerable<IcmMasLookUpType> Select(IcmMasLookUpType filter);

        [OperationContract]
        List<SelectListItem> MasLookUpTypeSelectList(int? LookUpTypeId);
    }

	[ServiceErrorBehavior(typeof(ElmahErrorHandler))]
    public class IcmMasLookUpTypeService : IIcmMasLookUpTypeService
    {
        GERPContext db = new GERPContext(false);

        public IEnumerable<IcmMasLookUpType> Select(IcmMasLookUpType filter)
        {
            return null;
        }

        public List<SelectListItem> MasLookUpTypeSelectList(int? LookUpTypeId)
        {
            var data = new List<SelectListItem>();

            try
            {
                List<Models.ICM.IcmMasLookUpType> listMasLookUpType = (from m in db.IcmMasLookUpTypes
                                                         where m.RecordStatus != Models.SYS.RecordStatus.DeletedStatus
                                                         select m).ToList();

                foreach (var MasLookUpType in listMasLookUpType)
                {
                    var item = new SelectListItem { Text = MasLookUpType.LookUpTypeName, Value = MasLookUpType.LookUpTypeId.ToString() };
                    if (MasLookUpType.LookUpTypeId == LookUpTypeId) item.Selected = true;
                    data.Add(item);
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return data;
        }
    }
}
